//
//  HYKaifuOrder.m
//  HaiYue
//
//  Created by tucici on 2019/3/20.
//  Copyright © 2019 skyline. All rights reserved.
//

#import "HYKaifuOrder.h"
#import "HYKaifuModel.h"
@implementation HYKaifuOrder
+ (NSMutableArray *)order:(HYKaifuList *)list
{
    NSMutableArray *arr_yj = [NSMutableArray array];
    NSMutableArray *arr_jr = [NSMutableArray array];
    NSMutableArray *arr_jj = [NSMutableArray array];
    
    NSString *time = [self time];
    for (HYKaifuModel *model in list.list)
    {
        int i = [self judgeTime:model.date time:time];
        
        if (i == 1)//已经开服
            [arr_yj addObject:model];
        else if (i == 2)//今日开服
            [arr_jr addObject:model];
        else //即将开服
            [arr_jj addObject:model];
    }
   return [NSMutableArray arrayWithObjects:@{@"已开服":arr_yj},@{@"今日开服":arr_jr},@{@"即将开服":arr_jj}, nil];
}

/**
 1是已经开服，2是今日开服，3是即将开服
 
 @param string 开服日期
 @param time 当前日期
 @return 1是已经开服，2是今日开服，3是即将开服
 */
+ (int)judgeTime:(NSString *)string time:(NSString *)time;
{
    NSString *newString = [string substringToIndex:10];
    NSString *year = [newString substringWithRange:NSMakeRange(0, 4)];
    NSString *month = [newString substringWithRange:NSMakeRange(5, 2)];
    NSString *day = [newString substringWithRange:NSMakeRange(8, 2)];
    
    //当前时间
    NSString *timeY = [time substringWithRange:NSMakeRange(0, 4)];
    NSString *timeM = [time substringWithRange:NSMakeRange(5, 2)];
    NSString *timeD = [time substringWithRange:NSMakeRange(8, 2)];
    
    if ([year intValue] > [timeY intValue])
        return 3;
    else if ([year intValue] < [timeY intValue])
        return 1;
    else
    {
        if ([month intValue] > [timeM intValue])
            return 3;
        else if ([month intValue] < [timeM intValue])
            return 1;
        else
        {
            if ([day intValue] > [timeD intValue])
                return 3;
            else if ([day intValue] < [timeD intValue])
                return 1;
            else
                return 2;
        }
    }
    
}
+ (NSString *)time
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    
    NSDate *datenow = [NSDate date];
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    return currentTimeString;
}
@end
